/**
 * Copyright 2009 Henning Teek, Ingo Renner
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.chigs.web.doku.attachment;

import com.googlecode.chigs.domain.Attachment;
import com.googlecode.chigs.domain.ConfigLocation;
import org.apache.wicket.authorization.strategies.role.annotations.AuthorizeInstantiation;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.ChoiceRenderer;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.model.StringResourceModel;

import java.util.List;

/**
 * 
 * @author Ingo Renner
 * @author Henning Teek
 *
 */
@AuthorizeInstantiation("ROLE_USER")
public class EditAttachmentFormularPanel extends Panel {
	public EditAttachmentFormularPanel(String id, IModel<Attachment> model, List<ConfigLocation> locations) {
		super(id);
		StringResourceModel lFileName = new StringResourceModel("filename.label", EditAttachmentFormularPanel.this, null);
		add(new Label("filename.label", lFileName));
		add(new TextField<String>("filename", new PropertyModel<String>(model.getObject(), "filename"))
				.setRequired(true)
				.setLabel(lFileName));
		
		StringResourceModel lDescription = new StringResourceModel("description.label", EditAttachmentFormularPanel.this, null);
		add(new Label("description.label", lDescription));
		add(new TextField<String>("description", new PropertyModel<String>(model.getObject(), "description"))
				.setRequired(false)
				.setLabel(lDescription));
		
		final boolean locreq = false;
		StringResourceModel lConfigLocation = new StringResourceModel("configLocation.label", EditAttachmentFormularPanel.this, null);
		add(new Label("configLocation.label", lConfigLocation));
		add(new DropDownChoice<ConfigLocation>("configLocation", 
				new PropertyModel<ConfigLocation>(model.getObject(), "configLocation"), 
				locations, 
				new ChoiceRenderer<ConfigLocation>("name", "id"))
				.setNullValid(true)
				.setRequired(locreq)
			.setLabel(lConfigLocation));
	}
}
